package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Idea;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class IdeaDao {
	
	private DBHelp<Idea> db = new DBHelp<Idea>();
	
	public void Save (String id,String content,String createtime,String t_employee_id,String t_project_id) {
		String sql = "insert into t_idea(id,content,createtime,t_employee_id,t_project_id) values(?,?,?,?,?)";
		db.executeSQL(sql, id,content,createtime,t_employee_id,t_project_id);
	}
	
	public List<Idea> FindAll () {
		String sql = "select id,content,createtime,t_employee_id,t_project_id from t_idea";
		return db.executeQueryForList(sql, new IdeaRowMapper());
	}

	private class IdeaRowMapper implements RowMapper<Idea> {
		
		public Idea mapperRow (ResultSet rs) throws SQLException {
			
			Idea idea = new Idea();
			idea.setId(rs.getString("id"));
			idea.setContent(rs.getString("content"));
			idea.setCreatetime(rs.getString("createtime"));
			idea.setT_employee_id(rs.getString("t_employee_id"));
			idea.setT_project_id(rs.getString("t_project_id"));
			return idea;
		}
	}
}
